package com.buaa.controller;

import cn.hutool.core.date.DateUtil;
import com.buaa.common.Result;
import com.buaa.enums.ResponseCode;
import com.kimi.Message;
import com.kimi.MoonshotAiUtils;
import com.kimi.RoleEnum;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/home")
public class KimiController {
    // 演示用，实际要存入用户session


//    public static void main (String[] args) throws Exception{
////        chat("请告诉我北航的地址");
//    }
    @GetMapping ("/chat")
    public Result chatSession(@RequestParam  String userName) {
          List<Message> messages = new ArrayList<>();
            Message message = new Message(RoleEnum.user.name(), userName);
            messages.add(message);
            // 模型列表 https://platform.moonshot.cn/docs/intro#%E6%A8%A1%E5%9E%8B%E5%88%97%E8%A1%A8
        System.out.println(DateUtil.now() + " -> Question:" + userName);
        String result = MoonshotAiUtils.chat("moonshot-v1-8k", messages);
        System.out.println(DateUtil.now() + " -> Answer:" + result);
        return Result.success(ResponseCode.QA_SUCCESS.getKey(), ResponseCode.QA_SUCCESS.getDesc(), result);
     }
}
